# Contributor: Leo <thinkabit.ukim@gmail.com>
# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Daniel Sabogal <dsabogalcc@gmail.com>
# Maintainer: Simon Zeni <simon@bl4ckb0ne.ca>
pkgname=libinput
pkgver=1.25.0
pkgrel=0
pkgdesc="Library for handling input devices"
url="https://www.freedesktop.org/wiki/Software/libinput"
arch="all"
license="MIT"
_depends_tools="
	py3-libevdev
	py3-udev
	py3-yaml
	python3
	"
depends_dev="
	eudev-dev
	"
makedepends="
	$_depends_tools
	$depends_dev
	gtk+3.0-dev
	libevdev-dev
	meson
	mtdev-dev
	"
checkdepends="
	bash
	check-dev
	py3-pytest
	"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-libs
	$pkgname-udev
	$pkgname-debug-gui:_debug_gui
	$pkgname-tools
	$pkgname-zsh-completion
	"
install="$pkgname.post-upgrade"
source="https://gitlab.freedesktop.org/libinput/libinput/-/archive/$pkgver/libinput-$pkgver.tar.gz"

# secfixes:
#   1.20.1-r0:
#     - CVE-2022-1215

build() {
	abuild-meson \
		-Db_lto=true \
		-Ddocumentation=false \
		-Dlibwacom=false \
		-Ddebug-gui=true \
		-Dtests="$(want_check && echo true || echo false)" \
		. output
	meson compile -C output
}

check() {
	meson test --no-rebuild --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
}

libs() {
	default_libs

	amove usr/share/libinput
}

udev() {
	install_if="$pkgname-libs=$pkgver-r$pkgrel eudev"

	amove usr/lib/udev
}

tools() {
	pkgdesc="CLI helper tools for debugging libinput"
	depends="$pkgname=$pkgver-r$pkgrel $_depends_tools"

	# Q: Maybe move all tools (even libinput-list-devices, libinput-quirks)
	#    into -tools? (jirutka)
	amove usr/libexec/libinput/libinput-analyze*
	amove usr/libexec/libinput/libinput-debug*
	amove usr/libexec/libinput/libinput-measure*
	amove usr/libexec/libinput/libinput-record
	amove usr/libexec/libinput/libinput-replay
}

_debug_gui() {
	pkgdesc="GTK-based visual debug helper for libinput"
	depends=""

	amove usr/libexec/libinput/libinput-debug-gui
}

sha512sums="
17c668d04e3ff7d3e99519f7e7fe37377bd25e90ff36acc8c3f06f6de31265514780a0823b6fbd5712272a6b6f759bf768cb35b4f68c29828c1964899e9ee752  libinput-1.25.0.tar.gz
"
